package com.stoken.web.control;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.stoken.domain.User;
import com.stoken.service.UserService;
import com.stoken.web.StokenUtils;
import com.symbio.commons.Page;
import com.symbio.utils.WebUtils;

@Controller
@RequestMapping("/user")
public class UserControl {
	
	@Autowired
	private UserService userService;
	
	/**
	 * 增加用户
	 * @param name 用户名
	 */
	@RequestMapping("/add")
	public void addUser(User user){
		
		userService.save(user);
		System.out.println("增加数据： ");
	}
	
	@RequestMapping("/list")
	public String list(HttpServletRequest request,ModelMap modeMape)
	{
		
		return "/user/list";
	}
	
	@RequestMapping("/listPage")
	public String listPage(HttpServletRequest request,ModelMap modeMape)
	{
		Page<User> pageData = new Page<User>();
		//pageData.setPageSize(StokenUtils.pageSize);
		//给pageData设置参数
		WebUtils.setPageDataParameter(request, pageData);
		pageData.setPageSize(10);
		pageData = userService.find(pageData);		
		modeMape.addAttribute("test", "照明");
		
	    System.out.println("ddd "+pageData.getResult().size());
	    modeMape.addAttribute("pageData", pageData);
		return "/user/userPage";
	}
	

}
